POV-Ray : Newsgroups : povray.text.scene-files : power notation change in POV3.6? : Re: power notation change in POV3.6? Server Time
21 Jun 2024 16:42:25 EDT (-0400)
  Re: power notation change in POV3.6?  
From: Warp
Date: 18 Sep 2006 09:12:29
Message: <450e9b3d@news.povray.org>
Mike Williams <nos### [at] econymdemoncouk> wrote:
> a*b^c*d might mean different things depending on the order in which the
> operators are applied

  No, that's not the problem. The exponentiation operator as unambiguously
a higher precedence than the multiplication operator and thus that
expression is (well, should be) evaluated as a*(b^c)*d.

  The problematic cases, however, are these two: -a^2 and a^b^c

  In other words, is the precedence of the exponentiation operator lower
or higher than the precedence of the unary minus in the base? And in the
second case: Should the exponentiation operator be interpreted from
left-to-right (as most other operators) or right-to-left?

  The general consensus globally (ie. outside the POV world) is that
the exponentiation operator should have higher precedence than the
unary minus of the base. In other words, the first expression should
be interpreted as "-(a^2)" and not as "(-a)^2".
  Note that a unary minus in the exponent should, naturally, have a
higher precedence so that expressions like "a^-2" will work.

  As for the second expression, the general consensus seems to be
that the exponentiation operator, unlike most other operators, should
be interpreted from right-to-left. In other words, the second expression
should be interpreted as "a^(b^c)". This is because it more intuitively
represents how exponentiation (ie. superscript) works in mathematics.

  The problem with POV-Ray is that it didn't follow either of these
consensuses and this caused some complaints. The pov-team didn't want
to get into a filosophical discussion about what is the correct way
to interpret the ^ operator so they just removed it and now pow() is
the only official way for exponentiation.

  Note that it's only a question of agreement. It's not a question of
technical difficulties. It is trivial to parse the ^ operator
unambiguously with the precedence rules conforming to the global
consensus (iow. it doesn't even require ugly hacks nor ugly exceptions
in the parsing code, as long as the parsing code is already clean).

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.